#include "listado_codigo.h"

using namespace Gtk;

ListadoCodigo::ListadoCodigo() : ListViewText(3, false, SELECTION_SINGLE) {
	set_enable_search(false);
	set_column_title(0, "Direccion");
	set_column_title(1, "Opcode");
	set_column_title(2, "Instruccion");
	for (int i = 0; i < 10; i++) {
		append_text("0100:0000h");
		set_text(i, 1, "F9 A2");
		set_text(i, 2, "MOV AX, AX");
	}
	get_selection()->set_select_function(sigc::mem_fun(*this, &ListadoCodigo::on_select));
	selected_row_ = -1;
}

void ListadoCodigo::select(int row)
{
	if (row >= 0 && row < get_model()->children().size()) {
		selected_row_ = row;
		get_selection()->select(get_model()->children()[row]);
	}
}

void ListadoCodigo::unselect_all()
{
	selected_row_ == -1;
	get_selection()->unselect_all();
}

bool ListadoCodigo::on_select(const Glib::RefPtr<TreeModel>& model,
                              const TreeModel::Path& path, bool path_currently_selected)
{
	return path_currently_selected || path[0] == selected_row_;
}
